package com.zygh.dlqwservice.module.controller.pc;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import com.zygh.dlqwservice.common.anno.OperateLog;
import com.zygh.dlqwservice.common.anno.PcLog;
import com.zygh.dlqwservice.common.pcdomain.ResponseDTO;
import com.zygh.dlqwservice.config.token.RequestTokenBO;
import com.zygh.dlqwservice.constant.SwaggerTagConst;
import com.zygh.dlqwservice.module.entity.SysUser;
import com.zygh.dlqwservice.module.entity.vo.SysUserUpdatePwdVO;
import com.zygh.dlqwservice.module.service.ISysUserService;
import com.zygh.dlqwservice.util.SmartRequestTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/sys-user")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_USER})
@OperateLog
public class SysUserController {
    @Resource
    private ISysUserService sysUserService;

    @PostMapping("/query")
    @ApiOperation(value = "员工管理查询")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USER, content = "员工管理查询")
    public ResponseDTO<PageInfo<SysUser>> query(Integer current, Integer size) {
        return sysUserService.findSysUserAll(current, size);
    }

    @ApiOperation(value = "添加员工")
    @PostMapping("/addSysUser")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_USER, content = "添加员工")
    public ResponseDTO addSysUser(@Valid @RequestBody SysUser sysUser) {
        return sysUserService.addSysUser(sysUser);
    }

    @ApiOperation(value = "修改密码")
    @PostMapping("/updatePwd")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_USER, content = "修改密码")
    public ResponseDTO<String> updatePwd(@Valid @RequestBody SysUserUpdatePwdVO updatePwd) {
        RequestTokenBO requestToken = SmartRequestTokenUtil.getRequestUser();
        return sysUserService.updatePwd(updatePwd, requestToken);
    }

    @ApiOperation(value = "根据部门id查询该部门下的警员")
    @PostMapping("/findSysUserByid")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USER, content = "根据部门id查询该部门下的警员")
    public ResponseDTO<List<SysUser>> findSysUserByid(@RequestBody String id) {
        return sysUserService.findSysUserByid(id);
    }

    @ApiOperation(value = "根据大队部门id查询该大队下的所有警员")
    @PostMapping("/findSysUserByDeptid")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USER, content = "根据大队部门id查询该大队下的所有警员")
    public ResponseDTO<List<SysUser>> findSysUserDeptid(@RequestBody String id) {
        return sysUserService.findSysUserByDeptid(id);
    }

    @ApiOperation(value = "根据警员查询警员")
    @PostMapping("/findByWarningsignal")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USER, content = "根据警员查询警员")
    public ResponseDTO<SysUser> findByWarningsignal(@RequestBody String warningsignal) {
        return sysUserService.findByWarningsignal(warningsignal);
    }



}
